<template>
  <div class="div">
    <div class="login">
      <div class="img">
        <img src="@/assets/logo.png" alt="" />
      </div>
      <el-form :model="loginForm" :rules="ruleLogin" ref="reflogin">
        <el-form-item prop="username">
          <el-input
          prefix-icon="el-icon-user-solid"
            v-model="loginForm.username"
            placeholder="请输入用户名"
            style="width: 470px; margin-left: 15px; margin-top: 100px"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
          type="password"
          show-password
            v-model="loginForm.password"
            placeholder="请输入密码"
            style="width: 470px; margin-left: 15px"
          ></el-input>
        </el-form-item>

        <el-button type="primary" style="margin-left: 320px" @click="login">登录</el-button>
        <el-button type="info" @click="chong">重置</el-button>
      </el-form>
    </div>
  </div>
</template>

<script>
import {loginApi} from '@/http/api'
  export default {
    data() {
        return {
            loginForm: {
                username:"admin",
                password:"123456"
            },
            ruleLogin:{
                username:[
                    {required:true,message:'请输入用户名',trigger:'blur'},
                    {min:5,max:15,message:'长度在5-15个字符',trigger:'blur'},
                ],
                password:[
                    {required:true,message:'请输入密码',trigger:'blur'},
                    {min:5,max:15,message:'长度在5-15个字符',trigger:'blur'},
                ],
            }
        }
    },
    methods:{
        login(){
            this.$refs.reflogin.validate((valid)=>{
                console.log('登陆结果:',valid);
                if(!valid) return
                loginApi(this.loginForm).then(res=>{
                    console.log('登陆成功的结果' );
                })
            })
        },
        chong(){
          this.loginForm.username=""
          this.loginForm.password=""
        }
    }     
  }
</script>

<style lang="scss" scoped>
body,
html,
.div {
  width: 100%;
  height: 100%;
  background-color: cadetblue;
  position: relative;
  .login {
    width: 500px;
    height: 300px;
    background-color: white;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0px 0px 10px white;
    .img {
      width: 150px;
      height: 150px;
      border: 8px solid pink;
      border-radius: 50%;
      position: absolute;
      top: -95px;
      left: 160px;
      box-shadow: 0px 0px 40px pink;
      img {
        width: 150px;
        height: 150px;
        border-radius: 50%;
      }
    }
  }
}
</style>